package com.lims.gson;

import com.google.gson.JsonElement;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author limaosheng
 * @create 2024-03-27 15:54
 * @desc
 */
public class LocalDateTimeSerializer implements JsonSerializer<LocalDateTime> {

    //对象转成json格式，时间格式指定
    @Override
    public JsonElement serialize(LocalDateTime src, java.lang.reflect.Type typeOfSrc, JsonSerializationContext context) {
        return new com.google.gson.JsonPrimitive(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss").format(src));
    }
}
